//Victor Visoki 317515427
//Ahia Lieber 301416418

#include "Array_t.h"
#include "Dlist_t.h"
#include<iostream>
using namespace std;

//Static memebers
int Array_t<int>::expandValue = 4;

int main(int argv,  char *argc){
	bool cont = true;
	unsigned int c;
	int choice = 0;
	Container_t<int> *test;
	cout	<< "Enter your integers container (1 for ARRAY, 2 for DLIST) :" << endl;
	cin		>> choice;

	switch(choice){
		case 1:
			try{
				test = new Array_t<int>();
			}catch(exception& e){
				cout << "Cannot create array " << e.what() << endl;
				return -1;
			}
			cout << "Array of integers was created" << endl;
			break;
		case 2:
			try{
				test = new Dlist_t<int>();
			}catch(exception& e){
				cout << "Cannot create dlist " << e.what() << endl;
				return -1;
			}
			cout << "Dlist of integers was created" << endl;
		default:
			try{
				test = new Dlist_t<int>();
			}catch(exception& e){
				cout << "Cannot create dlist " << e.what() << endl;
				return -1;
			}
			cout << "Dlist of integers was created" << endl;
	}
	int param, index;
	bool res;
	while(cont){
		cout	
				<< "	0: insert"				<< endl
				<< "	1: append"				<< endl
				<< "	2: prepend"				<< endl
				<< "	3: remove"				<< endl
				<< "	4: removeAndDelete"		<< endl
				<< "	5: removeAll"			<< endl
				<< "	6: removeAndDeleteAll"	<< endl
				<< "	7: find"				<< endl
				<< "	8: count"				<< endl
				<< "	9: print"				<< endl
				<< "Enter your choice : ";
		cin >> c;

		switch(c){
			case 0:
				cout << "Insert - please enter an integer: " << endl;
				cin >> param;
				try{
					test->insert(new int(param));
				}catch(exception& e){
					cout << "Insert failed with exception " << e.what() << endl;
				}
				break;
			case 1:
				cout << "Append - please enter an integer: " << endl;
				cin >> param;
				cout << "Append - please enter an index: " << endl;
				cin >> index;
				try{
					test->append(new int(param),index);
				}catch(exception& e){
					cout << "Append failed with exception " << e.what() << endl;
				}
				break;
			case 2:
				cout << "Prepend - please enter an integer: " << endl;
				cin >> param;
				cout << "Prepend - please enter an index: " << endl;
				cin >> index;
				try{
					test->prepend(new int(param),index);
				}catch(exception& e){
					cout << "Prepend failed with exception " << e.what() << endl;
				}
				break;
			case 3:
				cout << "Remove - please enter an integer: " << endl;
				cin >> param;
				res = test->remove(param);
				if(!res){
					cout << "Remove failed" << endl;
				}
				break;
			case 4:
				cout << "RemoveAndDelete - please enter an integer: " << endl;
				cin >> param;
				res = test->removeAndDelete(param);
				if(!res){
					cout << "RemoveAndDelete failed" << endl;
				}
				break;
			case 5:
				cout << "RemoveAll" << endl;
				res = test->removeAll();
				if(!res){
					cout << "RemoveAll failed" << endl;
				}
				break;
			case 6:
				cout << "RemoveAndDeleteAll" << endl;
				res = test->removeAndDeleteAll();
				if(!res){
					cout << "RemoveAndDeleteAll failed" << endl;
				}
				break;
			case 7:
				cout << "Find - please enter an integer: " << endl;
				cin >> param;
				if(test->find(param) == 0){
					cout << "Cannot find element" << endl;
				}else{
					cout << "Found element" << endl;
				}
				break;
			case 8:
				cout << "Number of elements " << test->count() << endl;;
				break;
			case 9:
				{
					cout << "Printing:" << endl;
					test->print();
				}
				break;
			default: cont = false;
		}
	}
	delete test;
	return 0;
}